package com.runa.rccprotocol.analysis.langkabo;

import com.runa.protocol.analysis.MetaBufferAnalysis;
import com.runa.protocol.analysis.ShellBufferAnalysis;
import com.runa.protocol.dto.DtuReport;
import com.runa.protocol.dto.DtuReportAck;
import com.runa.protocol.util.ByteUtil;
import com.runa.rccprotocol.analysis.RunaDeviceAnalysis;
import com.runa.rccprotocol.dto.langkabo.LKBAck;

/**
 * 琅卡博宁晋项目透传采集器
 */
public class LangKaBaoNjFmuAnalysis extends ShellBufferAnalysis<byte[]> {


    public LangKaBaoNjFmuAnalysis(MetaBufferAnalysis analysis) {
        super(analysis, 0);
    }

    @Override
    public int fill(byte[] data, int length, String n) {
        if (data[0] == 0x68 && data[1] == (byte) 0xc9) {
            netEquNo = ByteUtil.byteToHexStringFlip(data, 2, 7);
            DtuReport register = new DtuReport(netEquNo);
            register.setMustAck(true);
            DtuReportAck ack = new LKBAck(netEquNo);
            register.setAck(ack);
            interData = register;
        } else if (data[0] == 0x68 && data[1] == 0) {
            netEquNo = ByteUtil.byteToHexStringFlip(data, 2, 7);
            DtuReport register = new DtuReport(netEquNo);
            register.setMustAck(true);
            byte[] bytes = new byte[12];
            System.arraycopy(data, 0, bytes, 0, bytes.length);
            DtuReportAck ack = new LKBAck(bytes);
            register.setAck(ack);
            interData = register;
        } else {
            analysis.fill(data, length, netEquNo);
            interData = analysis.gain();
        }
        return 0;
    }

    public static void main(String[] args) {
        LangKaBaoNjFmuAnalysis analysis = new LangKaBaoNjFmuAnalysis(new RunaDeviceAnalysis());
        byte[] bytes = ByteUtil.hexStringToBytes("FEFEFE6841716211640000008123F19000FF000000006000300005015019070411200001501406FEFEFEFEFEFEFEFEFEFEA716 ");
        analysis.fill(bytes, bytes.length, null);
        System.out.println(analysis.gain());
    }
}
